package com.lzy.util;

import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.StringUtils;

import java.util.UUID;

/**
 * @author G by 2019/9/11 14:22
 */
public class LogUtil {
    /**
     * 获取request中的uuid，如果不存在，生成一个uui再返回
     *
     * @param request 请求request
     * @return
     */
    public static String getUuid(ServerHttpRequest request) {
        String uuid = request.getHeaders().getFirst("uuid");
        if (StringUtils.isEmpty(uuid)) {
            return UUID.randomUUID().toString().replaceAll("-", "");
        }
        return uuid;
    }



}
